<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\ChannelRelayUserDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateChannelRelayUserRequest;
use App\Http\Requests\UpdateChannelRelayUserRequest;
use App\Repositories\ChannelRelayUserRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class ChannelRelayUserController extends AppBaseController
{
    /** @var  ChannelRelayUserRepository */
    private $channelRelayUserRepository;

    public function __construct(ChannelRelayUserRepository $channelRelayUserRepo)
    {
        $this->channelRelayUserRepository = $channelRelayUserRepo;
    }

    /**
     * Display a listing of the ChannelRelayUser.
     *
     * @param ChannelRelayUserDataTable $channelRelayUserDataTable
     * @return Response
     */
    public function index(ChannelRelayUserDataTable $channelRelayUserDataTable)
    {
        return $channelRelayUserDataTable->render('backend.channel_relay_users.index');
    }

    /**
     * Show the form for creating a new ChannelRelayUser.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.channel_relay_users.create');
    }

    /**
     * Store a newly created ChannelRelayUser in storage.
     *
     * @param CreateChannelRelayUserRequest $request
     *
     * @return Response
     */
    public function store(CreateChannelRelayUserRequest $request)
    {
        $input = $request->all();

        $channelRelayUser = $this->channelRelayUserRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Channel Relay User']));

        return redirect(route('channelRelayUsers.index'));
    }

    /**
     * Display the specified ChannelRelayUser.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $channelRelayUser = $this->channelRelayUserRepository->findWithoutFail($id);

        if (empty($channelRelayUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay User']));

            return redirect(route('channelRelayUsers.index'));
        }

        return view('backend.channel_relay_users.show')->with('channelRelayUser', $channelRelayUser);
    }

    /**
     * Show the form for editing the specified ChannelRelayUser.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $channelRelayUser = $this->channelRelayUserRepository->findWithoutFail($id);

        if (empty($channelRelayUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay User']));

            return redirect(route('channelRelayUsers.index'));
        }

        return view('backend.channel_relay_users.edit')->with('channelRelayUser', $channelRelayUser);
    }

    /**
     * Update the specified ChannelRelayUser in storage.
     *
     * @param  int              $id
     * @param UpdateChannelRelayUserRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateChannelRelayUserRequest $request)
    {
        $channelRelayUser = $this->channelRelayUserRepository->findWithoutFail($id);

        if (empty($channelRelayUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay User']));

            return redirect(route('channelRelayUsers.index'));
        }

        $channelRelayUser = $this->channelRelayUserRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Channel Relay User']));

        return redirect(route('channelRelayUsers.index'));
    }

    /**
     * Remove the specified ChannelRelayUser from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $channelRelayUser = $this->channelRelayUserRepository->findWithoutFail($id);

        if (empty($channelRelayUser)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Channel Relay User']));

            return redirect(route('channelRelayUsers.index'));
        }

        $this->channelRelayUserRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Channel Relay User']));

        return redirect(route('channelRelayUsers.index'));
    }
}
